﻿// Decompiled with JetBrains decompiler
// Type: SP1.Convertor
// Assembly: SP1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 4A78F1E7-7FD5-407C-8917-5F99ECC43C34
// Assembly location: C:\Users\KasimGulcan\Desktop\Project\DynaCAD\bin\Debug\SP1.dll

using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Xml;

namespace SP1
{
  public static class Convertor
  {
    public static Viewbox Svg2Viewbox(string FilePath)
    {
      return Convertor.XmlDocumenttoViewBox(Convertor.SvgFiletoXmlDocument(FilePath));
    }

    public static XmlDocument SvgFiletoXmlDocument(string FilePath)
    {
      XmlNamespaceManager nsMgr = new XmlNamespaceManager((XmlNameTable) new NameTable());
      nsMgr.AddNamespace("xlink", "urn:ignore");
      XmlParserContext context = new XmlParserContext((XmlNameTable) null, nsMgr, (string) null, XmlSpace.None);
      StreamReader streamReader = new StreamReader(FilePath);
      string str1 = streamReader.ReadToEnd();
      streamReader.Close();
      string str2 = str1.Replace("!DOCTYPE", "!--DosyaTipi");
      for (int startIndex1 = 0; startIndex1 < str2.Length; ++startIndex1)
      {
        if ((int) str2[startIndex1] == 33 && (int) str2[startIndex1 + 1] == 45)
        {
          int startIndex2 = str2.IndexOf('>', startIndex1);
          if ((int) str2[startIndex2 - 1] != 45 || (int) str2[startIndex2 - 2] != 45)
          {
            str2 = str2.Insert(startIndex2, "--");
            break;
          }
          break;
        }
      }
      StreamWriter streamWriter = new StreamWriter(FilePath);
      streamWriter.Write(str2);
      streamWriter.Close();
      FileStream fileStream = new FileStream(FilePath, FileMode.Open);
      XmlTextReader xmlTextReader = new XmlTextReader((Stream) fileStream, XmlNodeType.Element, context);
      XmlDocument xmlDocument = new XmlDocument();
      xmlDocument.Load((XmlReader) xmlTextReader);
      fileStream.Close();
      return xmlDocument;
    }

    public static Viewbox XmlDocumenttoViewBox(XmlDocument XD)
    {
      //if (!File.Exists(Directory.GetCurrentDirectory() + "\\license"))
      //{
      //  int num = (int) MessageBox.Show("Lisans Dosyası Mevcut Değil!");
      //  return (Viewbox) null;
      //}
      //StreamReader streamReader = new StreamReader(Directory.GetCurrentDirectory() + "\\license");
      //string str = streamReader.ReadLine();
      //streamReader.Close();
      //string[] strArray = str.Split('-');
      //DateTime now = DateTime.Now;
      //DateTime dateTime = new DateTime(Convert.ToInt32(strArray[0].Substring(4)), Convert.ToInt32(strArray[0].Substring(2, 2)), Convert.ToInt32(strArray[0].Substring(0, 2)));
      //if (!(Encrypt.GetString(strArray[0], strArray[1]) == strArray[2]))
      //{
      //  int num = (int) MessageBox.Show("Geçersiz Lisans Dosyası!");
      //  return (Viewbox) null;
      //}
      //if (now > dateTime)
      //{
      //  int num = (int) MessageBox.Show("Lisans Süresi Dolmuştur!");
      //  return (Viewbox) null;
      //}
      Viewbox viewbox = new Viewbox();
      Console.WriteLine("Xaml Dosyası Oluşturuluyor...");
      if (XD.HasChildNodes)
      {
        foreach (XmlNode xn in XD.ChildNodes)
        {
          if (xn.Name == "svg")
            viewbox.Child = (UIElement) StructuralElement.CanvasCreator(xn);
        }
      }
      DefinitionElement.FEL.Clear();
      DefinitionElement.GEL.Clear();
      DefinitionElement.SL.Clear();
      DefinitionElement.UIL.Clear();
      return viewbox;
    }
  }
}
